package com.AppliGestion.client.RuleMakingSystem;


import com.AppliGestion.shared.model.RuleMakingSystem.data.Data;
import com.AppliGestion.shared.model.RuleMakingSystem.data.TypeData;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.data.RecordList;

import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.TransferImgButton;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.layout.HStack;

public class DataForm implements EntryPoint {
	
	public Data loadData(String location,String label){
		return new Data();
	}
	
	public void activateIfData(DataListGrid selectedData,IButton button){
		if(!button.isDisabled()){
			if(selectedData.getRecordList().isEmpty()) button.disable();
		}else{
			if(!selectedData.getRecordList().isEmpty()) button.enable();
		}
	}
	
	
	public void onModuleLoad() {
		
		DataListGrid availableDataList = new DataListGrid();		
		DataListGrid selectedDataList = new DataListGrid();
		selectedDataList.setCanEdit(true);
		
		DataRecord record1 = new DataRecord("param1",true,TypeData.NUMERIC.toString(),1.0);
		DataRecord record2 = new DataRecord("obs1",false,TypeData.NUMERIC.toString(),1.0);
		
		RecordList recordList = new RecordList();
		recordList.add(record1);
		recordList.add(record2);
				
		availableDataList.setData(recordList);
		
		/*
		final IButton verifyDataBouton = new IButton("Vérifier");
		verifyDataBouton.addClickHandler(new ClickHandler() {			
			public void onClick(ClickEvent event) {
				//if(!selectedDataList.getData().isDataStructure()){
					
				//}
			}			
		});
		
		final TransferImgButton addControl = new TransferImgButton(TransferImgButton.LEFT);
		addControl.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				selectedDataList.addData(availableDataList.getSelection());		
				//activateIfData(selectedDataList, verifyDataBouton);
			}
		});
		
		final IButton addButton = new IButton("Ajouter");
		addButton.addClickHandler(new ClickHandler() {			
			
			public void onClick(ClickEvent event) {
				selectedDataList.addData("Nouvelle donnée");
				//activateIfData(selectedDataList, verifyDataBouton);
			}
		});
		
		final IButton removeButton = new IButton("Enlever");
		removeButton.addClickHandler(new ClickHandler() {			
			
			public void onClick(ClickEvent event) {
				selectedDataList.removeSelectedData();
				//activateIfData(selectedDataList, verifyDataBouton);
				//activateIfData(selectedDataList, removeButton);				
			}
		});
		*/
		
						
		
		
		
		HStack grids = new HStack(10);  
        grids.setHeight(600);  
        grids.addChild(availableDataList);
        //grids.addChild(addButton);
        grids.addChild(selectedDataList);
        //grids.addChild(removeButton);
        //grids.addChild(verifyDataBouton);
  
        grids.draw();  
		
        
       
	}

}
